package model

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Phone            string `gorm:"type:char(11)" json:"phone"`
	Username         string `gorm:"type:varchar(30)" json:"username"`
	Password         string `gorm:"type:varchar(30)" json:"password"`
	AvatarUrl        string `gorm:"type:varchar(30)" json:"avatarUrl"`
	MemberId         int    `gorm:"type:int" json:"memberId"`
	MemberStatus     int    `gorm:"type:int" json:"memberStatus"` //0: 普通用户 1: vip用户 3: SVip用户
	MemberExpireTime int    `gorm:"type:int" json:"memberExpireTime"`
}

func (u *User) Register(db *gorm.DB) error {
	return db.Create(&u).Error
}

func (u *User) IsPhone(db *gorm.DB, phone string) error {
	return db.Where("phone = ?", phone).First(&u).Error
}

func (u *User) IsUser(db *gorm.DB, id int) error {
	return db.Where("id = ?", id).First(&u).Error
}

func (u *User) UpdateUserExpireTime(db *gorm.DB, id int, memberExpireTime int) error {
	return db.Model(&u).Where("id = ?", id).Update("member_expire_time", memberExpireTime).Error
}

func (u *User) GetUserMember(db *gorm.DB, id int) error {
	return db.Where("id = ?", id).First(&u).Error
}
